#include <iostream>
#include <list>
#include <algorithm>
using namespace std;

void test_list1()
{
	list<int> lt1 = { 10,3,2,3,4,5,6 };
	list<int>::iterator it = lt1.begin();

	while (it != lt1.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;

	for (auto e : lt1)
	{
		cout << e << " ";
	}
	cout << endl;

	//sort(lt1.begin(), lt1.end()); //不可以

	lt1.sort();
	for (auto e : lt1)
	{
		cout << e << " ";
	}
	cout << endl;

	lt1.sort(greater<int>());
	for (auto e : lt1)
	{
		cout << e << " ";
	}
	cout << endl;

	lt1.unique();
	for (auto e : lt1)
	{
		cout << e << " ";
	}
	cout << endl;

}



void test_list2()
{
	list<int> l1, l2;
	list<int>::iterator it;
	for (int i = 1; i <= 4; i++) l1.push_back(i);   // l1 : 1 2 3 4 
	for (int i = 1; i <= 3; i++) l2.push_back(i * 10); // l2 : 10 20 30

	it = l1.begin();
	++it; //point to 2

	//剪切链表2
	l1.splice(it, l2);   //l1 : 1 10 20 30 2 3 4 
	// l2 : empty;
	for (auto e : l1)
	{
		cout << e << " ";
	}
	cout << endl;

	auto it1 = find(l1.begin(), l1.end(), 3); // 算法库的find
	l1.splice(l1.begin(), l1, it1);// 把3转移到前面
	for (auto e : l1)
	{
		cout << e << " ";
	}
	cout << endl;
}


void test_list3()
{
	list<int> lt1 = { 10,3,2,3,4,5,6 };
	//auto it = lt1.begin() + 1;
	//it + 10;// 不支持这个重载运算符，但是++, --支持
}


int main()
{
	test_list2();

	return 0;
}